package hanjia;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/17-下午2:22
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode134 {


    public  int canCompleteCircuit(int[] gas,int[] cost){

        int total=0;
        int resultIndex=0;
        int current=0;

        for (int i=0;i<gas.length;i++){
            current+=gas[i]-cost[i];
            total+=gas[i]-cost[i];

            if (current<0){
                current=0;
                resultIndex=i+1;
            }

        }
        if (total>=0){
            return resultIndex;
        }
        return -1;



    }
}
